var bSubmitting = false;
function validate()
{
    bSubmitting = true;
    $("submit_btn").disabled = true;
    
    // page title
    page_title = $("annoration_title").value;
    if (page_title == "")
    {
        alert("Please enter a title for the web page.");
        $("submit_btn").disabled = false;
        bSubmitting = false;
        return false;
    }
    // page address
    page_uri = $("annoration_uri").value;
    if (page_uri == "")
    {
        alert("Please enter the address of the web page to annorate.");
        $("submit_btn").disabled = false;
        bSubmitting = false;
        return false;
    }
    history.back(1);
    return true;
}
var nSpecifiedRating;// = document.getElementById('rating').innerHTML / 2;
var bInStars = false;
var overColor = "";
var color = "";
function overStar(nRating)
{
    if (bSubmitting) return;
    bInStars = true;
	color = overColor;
    showRating(nRating);
}
function showRating(nRating)
{
	
    for (nStar = 1; nStar < 6; nStar++)
    {
        star = document.getElementById("star_" + nStar);
        star.src = "http://www.annorate.com/images/" + color + "star_" + (nStar <= nRating ? "filled" : "empty") + "_small.gif";
    }
}
function setRating(nRating)
{
    document.getElementById("rating").innerHTML=nRating;
}
function clickStar(nRating)
{
    if (bSubmitting) return;
    if (nSpecifiedRating == 1 && nRating == 1)
    {
        nSpecifiedRating = 0;
        setRating(0);
        showRating(0);
    }
    else
    {
        nSpecifiedRating = nRating;
        setRating(nRating);
    }
}

function change()
{
    if (!bInStars) showRating(nSpecifiedRating);
}
function leaveStars()
{
    if (bSubmitting) return;
    bInStars = false;
	color = "";
    setTimeout("change()",100);
}
function overStars()
{
    if (bSubmitting) return;
	color = overColor;
    bInStars = true;
}
function leaveStar()
{
    if (bSubmitting) return;
	color = "";
    bInStars = false;
}
function replaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}

function trimString (str) 
{
    str = this != window? this : str;
    return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
String.prototype.trim = trimString;
    
function $(id)
{
    return document.getElementById(id);
}

function launchAnnorate(uri)
{
	var my_window= window.open("http://www.annorate.com/annorations/new?u=" + uri + "&t=" + encodeURIComponent(document.title), "_blank", "width=750, height=500,toolbar=no, resizable=no, location=no, menubar=no, scrollbars=no, directories=no, titlebar=yes");
	my_window.focus();
}

function launchMiniAnnorate(uri)
{
	var my_window= window.open("http://www.annorate.com/annorations/anonymous?u=" + uri + "&t=" + encodeURIComponent(document.title), "_blank", "width=550, height=300,toolbar=no, resizable=no, location=no, menubar=no, scrollbars=no, directories=no, titlebar=yes");
	my_window.focus();
}
